from tortoise import fields
from .base import BaseModel, UserMixin, TimestampMixin, DeletedMixin
from tortoise.contrib.pydantic import pydantic_model_creator


class User(BaseModel, UserMixin, TimestampMixin, DeletedMixin):
    username = fields.CharField(max_length=50, unique=True, description="用户名")
    email = fields.CharField(max_length=100, unique=True, description="电子邮件")
    password = fields.CharField(max_length=255, description="密码")
    is_active = fields.BooleanField(default=True, description="是否激活")
    avatar = fields.CharField(max_length=500, null=True, description="头像URL")
    last_login = fields.DatetimeField(null=True, description="最后登录时间")

    class Meta:
        table = "sys_user"
        description = "用户表"


# 用户 Pydantic 模型，排除密码和删除标志字段
User_Pydantic = pydantic_model_creator(
    User, name="User", exclude=("password", "delete")
)
